from fastapi import APIRouter, Depends, HTTPException, status
from schemas.industry import IndustryResponse, IndustryBase
from services.industry_service import IndustryService
from schemas.base import create_response
import asyncio
import traceback

router = APIRouter(prefix="/industry", tags=["industry"])
service = IndustryService()

@router.get("/tree")
async def get_tree():
    try:
        tree = await service.get_tree()
        if not tree:
            response={"code": 404, "message": f"未查询到行业树"}
        else:    
            response = await create_response(200, "行业树查询成功", tree)
        return response
    except Exception as e:
        raise HTTPException(
            status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
            detail={
                "code": 500,
                "message": f"行业树查询失败: {str(e)}",
                
            }
        )